package net.hn.hnms.sys.system.controller.feign;

import cn.hutool.core.lang.tree.Tree;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.system.api.domain.SysDept;
import net.hn.hnms.sys.system.service.ISysDeptService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 部门信息
 *
 * @author wangjr
 */
@Validated
@Api(value = "部门控制器", tags = {"部门管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/remoteDept")
public class RemoteDeptController extends BaseController {

    private final ISysDeptService deptService;

    /**
     * 根据部门编号获取详细信息
     */
    @GetMapping(value = "/{deptIds}")
    public List<SysDept> getDeptByIds(@PathVariable("deptIds") List<Long> deptIds) {
        return deptService.selectBatchIds(deptIds);
    }



    @GetMapping(value = "/getDeptByOrganizationCode/{organizationCode}")
    public List<SysDept> getDeptByOrganizationCode(@PathVariable("organizationCode") String organizationCode) {
        SysDept sysDept = new SysDept();
        sysDept.setOrganizationCode(organizationCode);
        return deptService.getDeptByOrganizationCode(organizationCode);
//        return deptService.getDeptByOrganizationCode(organizationCode);
    }

    @PostMapping(value = "/getTreeSelectOrg")
    public List<Tree<Integer>> getTreeSelectOrg() {
        List<SysDept> depts = deptService.selectDeptOrgList(new SysDept());
        return deptService.buildDeptTreeSelectOrg(depts);
    }

}
